import { acceptHMRUpdate, defineStore } from 'pinia'

export const useUserStore = defineStore('user', () => {
  const savedName = ref('store_data_user_')
  const previousNames = ref(new Set())

  const usedNames = computed(() => Array.from(previousNames.value))
  const otherNames = computed(() => usedNames.value.filter(name => name !== savedName.value))

  function setNewName(name) {
    if (savedName.value)
      previousNames.value.add(savedName.value)

    savedName.value = name
  }

  return {
    setNewName,
    otherNames,
    savedName,
  }
})


export const useConfigStore = defineStore('config', {
  state: () => ({
    locale:'cn',
  }),
  actions: {
    setLocale(v) {
      this.locale = v
    }
  },
  persist: {
    enabled: true
  }
})

export const useCommon = defineStore('common', {
  state: () => ({
    currentSectionId: '123456',
  }),
  actions: {
    setCurrentSectionId(v) {
      this.currentSectionId = v
    },
  },
  persist: {
    enabled: true
  }
})


if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useUserStore, import.meta.hot))
}

